package no.ntnu.fp.watch.gui;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.FlowLayout;
import java.awt.GridLayout;

import javax.swing.DefaultListCellRenderer;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.ListCellRenderer;
import javax.swing.border.Border;
import javax.swing.border.LineBorder;

import org.apache.derby.iapi.services.io.LimitInputStream;


import no.ntnu.fp.model.Status;
import no.ntnu.fp.model.Well;

public class EventLogRenderer extends JPanel implements ListCellRenderer {
	
	JLabel left, middle, right, moreRight;
	
	public EventLogRenderer(){
		setLayout(new GridLayout(1, 4));
		left = new JLabel();
		right = new JLabel();
		moreRight = new JLabel();
		middle = new JLabel();
		
		left.setOpaque(true);
		middle.setOpaque(true);
		right.setOpaque(true);
		moreRight.setOpaque(true);
		
		add(left);
		add(middle);
		add(right);
		add(moreRight);
	}
	
	
	
	
	public Component getListCellRendererComponent(JList list, Object value,
			int index, boolean isSelected, boolean cellHasFocus) 
	{
		
		Event event = (Event)value;
		
		
		String text = "<html><div bgcolor="+event.getColorAsString()+" width=100 height=60></div></html>";
		left.setText(text);
		
		middle.setText("<html><span><p>"+event.getStarttime() + "- </p><p>" +event.getEndtime()+ "</p></html>");
		
		moreRight.setText("<html><p>Comment: "+event.getComment()+"</p></html>");
		
		if(event.isFalseAlarm() == 1){
			right.setText("<html><p>False Alarm</p></html>");
		}
		else{
			right.setText("");
		}
		
		
		if(isSelected){
			this.setBorder(new LineBorder(new Color(3, 181, 255)));
			left.setForeground(list.getSelectionForeground());
			left.setBackground(list.getSelectionBackground());
			middle.setForeground(list.getSelectionForeground());
			middle.setBackground(list.getSelectionBackground());
			right.setForeground(list.getSelectionForeground());
			right.setBackground(list.getSelectionBackground());
			moreRight.setForeground(list.getSelectionForeground());
			moreRight.setBackground(list.getSelectionBackground());
			
		}
		else{
			this.setBorder(new LineBorder(new Color(229, 231, 229)));
			left.setForeground(list.getForeground());
			left.setBackground(list.getBackground());
			middle.setForeground(list.getForeground());
			middle.setBackground(list.getBackground());
			right.setForeground(list.getForeground());
			right.setBackground(list.getBackground());
			moreRight.setForeground(list.getForeground());
			moreRight.setBackground(list.getBackground());
			
		}
		
		
		return this;
		
	}
	
}
